home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Apps / ArchiveUtils / tar / next / level-2 < prev    next >
Encoding:
Text File  |  1992-12-20  |  5.4 KB  |  171 lines

  1. #!/bin/sh 
  2. # file: level-2
  3. #
  4. # Run this script as root on the machine that has the tape drive, to make a
  5. # level-1 dump containing all files changed since the last full dump.
  6. #
  7. # If you give `now' as an argument, the dump is done immediately.
  8. # Otherwise, it waits until 1am.
  9. #
  10. # You must edit the file `backup-specs' to set the parameters for your site.
  11. #
  12. # Modifications by P. E. Cantrell to level-1 for a level-2
  13. # floppy disk dump. The level-2 dump will backup everything
  14. # since the most recent tape or floppy disk level-1 dump or
  15. # level-0 tape dump.
  16. # Added new files $fsname.level-1-floppy and $fsname.level-2-floppy
  17. # for use with level-2 floppy disk backups. We rewrite *.level-1-floppy
  18. # whenever we do a tape level-0 backup or a tape or floppy level-1
  19. # backup. $fsname.level-2-floppy would be used for a level-3 backup
  20. # if you wrote one.
  21. #
  22.  
  23. if [ ! -w / ]; then
  24.    echo The backup must be run as root,
  25.    echo or else some files will fail to be dumped.
  26.    exit 1
  27. else
  28.    false
  29. fi
  30.  
  31. # Get the values of BACKUP_DIRS and BACKUP_FILES, and other variables.
  32. . ./backup-specs-floppy-2
  33.  
  34. # Maybe sleep until around specified or default hour.
  35. #
  36. if [ "$1" != "now" ]; then
  37.    if [ "$1"x != x ]; then
  38.       spec=$1
  39.    else
  40.       spec=$BACKUP_HOUR
  41.    fi
  42.    pausetime=`date | awk '{hr=substr($4,1,2);\\
  43.       mn=substr($4,4,2);\\
  44.       if((hr+0)<spec)\\
  45.          print 3600*(spec-hr)-60*mn;\\
  46.       else\\
  47.          print 3600*(spec+(24-hr))-60*mn; }' spec=$spec`
  48.    clear
  49.    cat ./dont_touch
  50.    sleep $pausetime
  51. fi
  52.  
  53. # start doing things
  54.  
  55. here=`pwd`
  56. LOGFILE=log-`date | awk '{print $2 "-" $3 "-" $6}'`-level-2-floppy
  57. HOST=`hostname | sed 's/\..*//'`
  58. #TAR_PART1="/usr/local/bin/tar -c +multi-volume +one-file-system +block=$BLOCKING +sparse"
  59. TAR_PART1="/usr/local/bin/tar -c -z +one-file-system"
  60.  
  61. # Make sure the log file did not already exist.  Create it.
  62.  
  63. if [ -f $LOGFILE ] ; then
  64.    echo Log file $LOGFILE already exists.
  65.    exit 1
  66. else
  67.    touch $LOGFILE
  68. fi
  69.  
  70. #mt -f $TAPE_FILE rewind
  71.  
  72. if [ x != "x$BACKUP_DIRS" ] ; then
  73. set $BACKUP_DIRS
  74. while [ $# -ne 0 ] ; do
  75.    host=`echo $1 | sed 's/:.*$//'`
  76.    fs=`echo $1 | sed 's/^.*://'`
  77.    date=`date`
  78.    fsname=`echo $1 | sed 's/\//:/g'`
  79.  
  80.    TARFILE={$fsname}-level-2-`date | awk '{print $2 "-" $3 "-" $6}'`.tar.Z
  81.    if [ -f $FD_FILE/$TARFILE ] ; then
  82.      echo Output file $FD_FILE/$TARFILE already exists
  83.      exit 1
  84.    fi
  85.  
  86. # This filename must be absolute; it is opened on the machine that runs tar.
  87.    TAR_PART2="+listed=/etc/tar-backup/temp.level-2"
  88.    TAR_PART3="+label='level 2 floppy backup of $fs on $host at $date' -C $fs ."
  89.  
  90.    echo Backing up $1 level-2 at $date to floppy | tee -a $LOGFILE
  91.    echo Last level-1 dump on this filesystem: | tee -a $LOGFILE
  92.  
  93.    if [ $HOST != $host ] ; then
  94.      echo level-2 is only to floppy disk. | tee -a $LOGFILE
  95.      exit 1
  96.    else
  97.      ls -l /etc/tar-backup/$fsname.level-1-floppy 2>&1 | tee -a $LOGFILE
  98.      cp /etc/tar-backup/$fsname.level-1-floppy /etc/tar-backup/temp.level-2 2>&1 | tee -a $LOGFILE
  99.    fi
  100.  
  101.    # Actually back things up.
  102.  
  103.    if [ $HOST != $host ] ; then
  104.      exit 1
  105.    else
  106. # Using `sh -c exec' causes nested quoting and shell substitution
  107. # to be handled here in the same way rsh handles it.
  108.       sh -c "exec $TAR_PART1 -f $FD_FILE/$TARFILE $TAR_PART2 $TAR_PART3" \
  109.             2>&1 | tee -a $LOGFILE
  110.    fi
  111.    if [ $? -ne 0 ] ; then
  112.       echo Backup of $1 to floppy failed. | tee -a $LOGFILE
  113.       # I'm assuming that the tar will have written an empty
  114.       # file to the tape, otherwise I should do a cat here.
  115.    else
  116.       if [ $HOST != $host ] ; then
  117.          exit 1
  118.       else
  119.         mv -f /etc/tar-backup/temp.level-2 /etc/tar-backup/$fsname.level-2 2>&1 | tee -a $LOGFILE
  120.       fi
  121.    fi
  122.    shift
  123. done
  124. else
  125.   echo No Backup file systems specified | tee -a $LOGFILE
  126. fi
  127. #Dump any individual files requested.
  128.  
  129. if [ x != "x$BACKUP_FILES" ] ; then
  130.     TARFILE=misc-level-2-`date | awk '{print $2 "-" $3 "-" $6}'`.tar.Z
  131.    if [ -f $FD_FILE/$TARFILE ] ; then
  132.      echo Output file $FD_FILE/$TARFILE already exists
  133.      exit 1
  134.    fi
  135.  
  136.    date=`date`
  137.    TAR_PART2="+listed=/etc/tar-backup/temp.level-2"
  138.    TAR_PART3="+label='level-2 floppy backup of miscellaneous \
  139. directories and files at $date'" 
  140.  
  141.    echo Backing up level-2 miscellaneous directories and files at $date to floppy| tee -a $LOGFILE
  142.    echo "Directories and files:" | tee -a $LOGFILE
  143.    echo $BACKUP_FILES | tee -a $LOGFILE
  144.    echo " " | tee -a $LOGFILE
  145.    echo Last level-1 dump of these files: | tee -a $LOGFILE  
  146.    ls -l /etc/tar-backup/misc.level-1-floppy 2>&1 | tee -a $LOGFILE
  147.  
  148.    rm -f /etc/tar-backup/temp.level-2 2>&1 | tee -a $LOGFILE
  149.    cp /etc/tar-backup/misc.level-1-floppy /etc/tar-backup/temp.level-2 2>&1 | tee -a $LOGFILE
  150.  
  151. # Using `sh -c exec' causes nested quoting and shell substitution
  152. # to be handled here in the same way rsh handles it.
  153.    sh -c "exec $TAR_PART1 -f $FD_FILE/$TARFILE $TAR_PART2 $TAR_PART3 \
  154.     $BACKUP_FILES" 2>&1 | tee -a $LOGFILE
  155.    if [ $? -ne 0 ] ; then
  156.      echo Backup of level-2 miscellaneous files to floppy failed. | tee -a $LOGFILE
  157.      # I'm assuming that the tar will have written an empty
  158.      # file to the tape, otherwise I should do a cat here.
  159.    else
  160.      mv -f /etc/tar-backup/temp.level-2 /etc/tar-backup/misc.level-2 2>&1 | tee -a $LOGFILE
  161.    fi
  162. else
  163.    echo No miscellaneous directories or files specified | tee -a $LOGFILE
  164.    false
  165. fi
  166.  
  167.  
  168. echo Sending the dump log to $ADMINISTRATOR
  169. #cat $LOGFILE | sed -f logfile.sed > $LOGFILE.tmp
  170. /usr/ucb/mail -s "Results of backup to floppy on `date`" $ADMINISTRATOR < $LOGFILE
  171.